import Taro, { Component } from '@tarojs/taro';
import { View, Text, Picker, Input, Label, Radio, RadioGroup } from '@tarojs/components';
import './wanshanxinxi.scss'
import { AtAvatar, AtInput, AtButton } from 'taro-ui';
import app from '../../main'
export default class Wanshanxinxi extends Component {

  config = {
    navigationBarTitleText: '完善信息'
  }
  constructor() {
    super(...arguments)
    this.state = {
      doctor_id: this.$router.params.doctor_id,
      doctor:{},
      name: '',
      date: '',
      isCheck: '',
      sex: ['男', '女']
    }
  }
  onTimeChange = e => {
    this.setState({
      date: e.detail.value
    })
  }
  onSexChange = e => {
    this.setState({
      isCheck:this.state.sex[e.detail.value]
    })
  }
  handleChange(e, n) {
    this.setState({
      name:n
    })
    return n;
  }
  save() {
    let data ={
      name:this.state.name,
      gender:this.state.isCheck,
      birthday:this.state.date,
    }
    if (app.isEmpty(data.name)) {
      app.toastMessage('姓名不能为空');
      return;
    }
    if (app.isEmpty(data.gender)) {
      app.toastMessage('性别不能为空');
      return;
    }
    if (app.isEmpty(data.birthday)) {
      app.toastMessage('出生日期不能为空');
      return;
    }
    app.post('web/patient/save', data, (res) => {
      if(res.data.status == 200) {
        app.toastMessage('提交成功');
      }
      app.redirectTo('/pages/eyeDoctor/eyeDoctor');
    })
  }
  bindDoctor() {
    var me = this;
    app.post('web/patient/bind_doctor', {doctor_id: this.state.doctor_id}, function(res) {
      
    });
  }
  getDoctor() {
    var me = this;
    app.get('web/doctor/getById', {id: this.state.doctor_id}, function(res) {
      if (res.data.status == 200) {
        me.setState({
          doctor: res.data.result
        })
      }
    });
  }

  componentDidMount() { 
    this.bindDoctor();
    this.getDoctor();
  }

  render() {
    return (
      <View>
        {/* <View className='top'>
          <AtAvatar className='a' image={app.getPath(this.state.doctor.head_image)} circle />
          <View className='top-info'>
            <Text className='at-article__h3'>{this.state.doctor.name}</Text>
            <Text className='at-article__h3'>{this.state.doctor.position_title}</Text>
            <Text className='at-article__h3'>{this.state.doctor.hospital}</Text>
          </View>
        </View> */}
        <View className='d'>
          <Text className='at-article__p'>完善信息，以便给你最佳的建议</Text>
        </View>
        <View>
          <AtInput
            className='i'
            name='value'
            title='姓名'
            type='text'
            placeholder='请输入姓名'
            value={this.state.name}
            onChange={this.handleChange.bind(this, 'name')}
          />
          <View className='item'>
            <View className='item_label'>性别</View>
            <Picker mode='selector' range={this.state.sex} onChange={this.onSexChange.bind(this)}>
              <View className='item_value'>
              {
                this.state.isCheck ? this.state.isCheck : '请选择性别'
              }
              </View>
            </Picker>
          </View>
          <View className='item'>
            <View className='item_label'>出生日期</View>
            <Picker mode='date' onChange={this.onTimeChange.bind(this)}>
              <View className='item_value'>
              {
                this.state.date ? this.state.date : '请选择出生日期'
              }
              </View>
            </Picker>
          </View>
        </View>
        <View className='b'><AtButton type='primary' circle onClick={this.save.bind(this)}>提交</AtButton>
        </View>
      </View>
    )
  }
}
